<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: OpenCV4Android SDK</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../df/d65/tutorial_table_of_content_introduction.html">Introduction to OpenCV</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">OpenCV4Android SDK </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../d9/d3f/tutorial_android_dev_intro.html">Introduction into Android Development</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../d5/df8/tutorial_dev_with_OCV_on_Android.html">Android Development with OpenCV</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Vsevolod Glumov </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 3.0 </td></tr>
</table>
<dl class="section warning"><dt>Warning</dt><dd>This tutorial is deprecated.</dd></dl>
<p>This tutorial was designed to help you with installation and configuration of OpenCV4Android SDK.</p>
<p>This guide was written with MS Windows 7 in mind, though it should work with GNU Linux and Apple Mac OS as well.</p>
<p>This tutorial assumes you have the following software installed and configured:</p>
<ul>
<li>JDK</li>
<li>Android SDK and NDK</li>
<li>Eclipse IDE</li>
<li>ADT and CDT plugins for Eclipse</li>
</ul>
<p>If you need help with anything of the above, you may refer to our <a class="el" href="../../d9/d3f/tutorial_android_dev_intro.html">Introduction into Android Development</a> guide.</p>
<p>If you encounter any error after thoroughly following these steps, feel free to contact us via <a href="https://groups.google.com/group/android-opencv/">OpenCV4Android</a> discussion group or OpenCV <a href="https://forum.opencv.org">Q&amp;A forum</a>. We'll do our best to help you out.</p>
<h2>General info </h2>
<p>OpenCV4Android SDK package enables development of Android applications with use of OpenCV library.</p>
<p>The structure of package contents looks as follows: </p><pre class="fragment">OpenCV-2.4.9-android-sdk
|_ apk
|   |_ OpenCV_2.4.9_binary_pack_armv7a.apk
|   |_ OpenCV_2.4.9_Manager_2.18_XXX.apk
|
|_ doc
|_ samples
|_ sdk
|    |_ etc
|    |_ java
|    |_ native
|          |_ 3rdparty
|          |_ jni
|          |_ libs
|               |_ armeabi
|               |_ armeabi-v7a
|               |_ x86
|
|_ LICENSE
|_ README.android
</pre><ul>
<li><code>sdk</code> folder contains OpenCV API and libraries for Android:</li>
<li><code>sdk/java</code> folder contains an Android library Eclipse project providing OpenCV Java API that can be imported into developer's workspace;</li>
<li><code>sdk/native</code> folder contains OpenCV C++ headers (for JNI code) and native Android libraries (*.so and *.a) for ARM-v5, ARM-v7a and x86 architectures;</li>
<li><code>sdk/etc</code> folder contains Haar and LBP cascades distributed with OpenCV.</li>
<li><p class="startli"><code>apk</code> folder contains Android packages that should be installed on the target Android device to enable OpenCV library access via OpenCV Manager API (see details below).</p>
<p class="startli">On production devices that have access to Google Play Market (and Internet) these packages will be installed from Market on the first start of an application using OpenCV Manager API. But devkits without Market or Internet connection require this packages to be installed manually. Install the Manager.apk and optional binary_pack.apk if it needed. See <code>Manager Selection</code> for details.</p>
<dl class="section note"><dt>Note</dt><dd>Installation from Internet is the preferable way since OpenCV team may publish updated versions of this packages on the Market.</dd></dl>
</li>
<li><code>samples</code> folder contains sample applications projects and their prebuilt packages (APK). Import them into Eclipse workspace (like described below) and browse the code to learn possible ways of OpenCV use on Android.</li>
<li><code>doc</code> folder contains various OpenCV documentation in PDF format. It's also available online at <a href="http://docs.opencv.org">http://docs.opencv.org</a>. <dl class="section note"><dt>Note</dt><dd>The most recent docs (nightly build) are at <a href="http://docs.opencv.org/master">http://docs.opencv.org/master</a>. Generally, it's more up-to-date, but can refer to not-yet-released functionality. </dd></dl>
<dl class="todo"><dt><b><a class="el" href="../../dd/da0/todo.html#_todo000016">Todo:</a></b></dt><dd>I'm not sure that this is the best place to talk about OpenCV Manager</dd></dl>
</li>
</ul>
<p>Starting from version 2.4.3 OpenCV4Android SDK uses OpenCV Manager API for library initialization. OpenCV Manager is an Android service based solution providing the following benefits for OpenCV applications developers:</p>
<ul>
<li>Compact apk-size, since all applications use the same binaries from Manager and do not store native libs within themselves;</li>
<li>Hardware specific optimizations are automatically enabled on all supported platforms;</li>
<li>Automatic updates and bug fixes;</li>
<li>Trusted OpenCV library source. All packages with OpenCV are published on Google Play;</li>
</ul>
<h2>Manual OpenCV4Android SDK setup </h2>
<h3>Get the OpenCV4Android SDK</h3>
<ol type="1">
<li>Go to the <a href="http://sourceforge.net/projects/opencvlibrary/files/">OpenCV download page on SourceForge</a> and download the latest available version. This tutorial is based on this package: <a href="http://sourceforge.net/projects/opencvlibrary/files/opencv-android/2.4.9/OpenCV-2.4.9-android-sdk.zip/download">OpenCV-2.4.9-android-sdk.zip</a>.</li>
<li><p class="startli">Create a new folder for Android with OpenCV development. For this tutorial we have unpacked OpenCV SDK to the <code>C:\Work\OpenCV4Android\</code> directory.</p>
<dl class="section note"><dt>Note</dt><dd>Better to use a path without spaces in it. Otherwise you may have problems with ndk-build.</dd></dl>
</li>
<li><p class="startli">Unpack the SDK archive into the chosen directory.</p>
<p class="startli">You can unpack it using any popular archiver (e.g with 7-Zip):</p>
<div class="image">
<img src="../../android_package_7zip.png" alt="android_package_7zip.png"/>
</div>
<p class="startli">On Unix you can use the following command: </p><div class="fragment"><div class="line">unzip ~/Downloads/OpenCV-2.4.9-android-sdk.zip</div></div><!-- fragment --></li>
</ol>
<h3>Import OpenCV library and samples to the Eclipse</h3>
<ol type="1">
<li><p class="startli">Start Eclipse and choose your workspace location.</p>
<p class="startli">We recommend to start working with OpenCV for Android from a new clean workspace. A new Eclipse workspace can for example be created in the folder where you have unpacked OpenCV4Android SDK package:</p>
<div class="image">
<img src="../../eclipse_1_choose_workspace.png" alt="eclipse_1_choose_workspace.png"/>
</div>
</li>
<li><p class="startli">Import OpenCV library and samples into workspace.</p>
<p class="startli">OpenCV library is packed as a ready-for-use <a href="http://developer.android.com/guide/developing/projects/index.html#LibraryProjects">Android Library Project</a>. You can simply reference it in your projects.</p>
<p class="startli">Each sample included into the <code>OpenCV-2.4.9-android-sdk.zip</code> is a regular Android project that already references OpenCV library. Follow the steps below to import OpenCV and samples into the workspace:</p><ul>
<li><p class="startli">Right click on the Package Explorer window and choose Import... option from the context menu:</p>
<div class="image">
<img src="../../eclipse_5_import_command.png" alt="eclipse_5_import_command.png"/>
</div>
</li>
<li><p class="startli">In the main panel select General &ndash;&gt; Existing Projects into Workspace and press Next button:</p>
<div class="image">
<img src="../../eclipse_6_import_existing_projects.png" alt="eclipse_6_import_existing_projects.png"/>
</div>
</li>
<li><p class="startli">In the Select root directory field locate your OpenCV package folder. Eclipse should automatically locate OpenCV library and samples:</p>
<div class="image">
<img src="../../eclipse_7_select_projects.png" alt="eclipse_7_select_projects.png"/>
</div>
</li>
<li>Click Finish button to complete the import operation.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>OpenCV samples are indeed <b>dependent</b> on OpenCV library project so don't forget to import it to your workspace as well.</dd></dl>
<p>After clicking Finish button Eclipse will load all selected projects into workspace, and you have to wait some time while it is building OpenCV samples. Just give a minute to Eclipse to complete initialization.</p>
<div class="image">
<img src="../../eclipse_cdt_cfg4.png" alt="eclipse_cdt_cfg4.png"/>
</div>
<p class="startli">Once Eclipse completes build you will have the clean workspace without any build errors:</p>
<div class="image">
<img src="../../eclipse_10_crystal_clean.png" alt="eclipse_10_crystal_clean.png"/>
</div>
</li>
</ol>
<p><a class="anchor" id="tutorial_O4A_SDK_samples"></a></p><h3>Running OpenCV Samples</h3>
<p>At this point you should be able to build and run the samples. Keep in mind, that face-detection and Tutorial 2 - Mixed Processing include some native code and require Android NDK and NDK/CDT plugin for Eclipse to build working applications. If you haven't installed these tools, see the corresponding section of <a class="el" href="../../d9/d3f/tutorial_android_dev_intro.html">Introduction into Android Development</a>.</p>
<p><b>warning</b></p>
<p>Please consider that some samples use Android Java Camera API, which is accessible with an AVD.</p>
<dl class="section note"><dt>Note</dt><dd>Recent *Android SDK tools, revision 19+* can run ARM v7a OS images but they available not for all Android versions.</dd></dl>
<p>Well, running samples from Eclipse is very simple:</p>
<ul>
<li>Connect your device with adb tool from Android SDK or create an emulator with camera support.<ul>
<li>See <a href="http://developer.android.com/guide/developing/devices/index.html">Managing Virtual Devices</a> document for help with Android Emulator.</li>
<li>See <a href="http://developer.android.com/guide/developing/device.html">Using Hardware Devices</a> for help with real devices (not emulators).</li>
</ul>
</li>
<li><p class="startli">Select project you want to start in Package Explorer and just press Ctrl + F11 or select option Run &ndash;&gt; Run from the main menu, or click Run button on the toolbar.</p>
<dl class="section note"><dt>Note</dt><dd>Android Emulator can take several minutes to start. So, please, be patient. * On the first run Eclipse will ask you about the running mode for your application:</dd></dl>
<div class="image">
<img src="../../eclipse_11_run_as.png" alt="eclipse_11_run_as.png"/>
</div>
</li>
<li><p class="startli">Select the Android Application option and click OK button. Eclipse will install and run the sample.</p>
<p class="startli">Chances are that on the first launch you will not have the <a href="https://docs.google.com/a/itseez.com/presentation/d/1EO_1kijgBg_BsjNp2ymk-aarg-0K279_1VZRcPplSuk/present#slide=id.p">OpenCV Manager</a> package installed. In this case you will see the following message:</p>
<div class="image">
<img src="../../android_emulator_opencv_manager_fail.png" alt="android_emulator_opencv_manager_fail.png"/>
</div>
<p class="startli">To get rid of the message you will need to install OpenCV Manager and the appropriate OpenCV binary pack. Simply tap Yes if you have <em>Google Play Market</em> installed on your device/emulator. It will redirect you to the corresponding page on <em>Google Play Market</em>.</p>
<p class="startli">If you have no access to the <em>Market</em>, which is often the case with emulators - you will need to install the packages from OpenCV4Android SDK folder manually. See <code>Manager Selection</code> for details. </p><div class="fragment"><div class="line">&lt;Android SDK path&gt;/platform-tools/adb install &lt;OpenCV4Android SDK path&gt;/apk/OpenCV_2.4.9_Manager_2.18_armv7a-neon.apk</div></div><!-- fragment --><dl class="section note"><dt>Note</dt><dd>armeabi, armv7a-neon, arm7a-neon-android8, mips and x86 stand for platform targets:<ul>
<li>armeabi is for ARM v5 and ARM v6 architectures with Android API 8+,</li>
<li>armv7a-neon is for NEON-optimized ARM v7 with Android API 9+,</li>
<li>arm7a-neon-android8 is for NEON-optimized ARM v7 with Android API 8,</li>
<li>mips is for MIPS architecture with Android API 9+,</li>
<li>x86 is for Intel x86 CPUs with Android API 9+.</li>
</ul>
</dd>
<dd>
If using hardware device for testing/debugging, run the following command to learn its CPU architecture: <div class="fragment"><div class="line">adb shell getprop ro.product.cpu.abi</div></div><!-- fragment --> If you're using an AVD emulator, go Window &gt; AVD Manager to see the list of available devices. Click Edit in the context menu of the selected device. In the window, which then pop-ups, find the CPU field.</dd>
<dd>
You may also see section <code>Manager Selection</code> for details.</dd></dl>
<p>When done, you will be able to run OpenCV samples on your device/emulator seamlessly.</p>
</li>
<li><p class="startli">Here is Sample - image-manipulations sample, running on top of stock camera-preview of the emulator.</p>
<div class="image">
<img src="../../emulator_canny.png" alt="emulator_canny.png"/>
</div>
</li>
</ul>
<h2>What's next </h2>
<p>Now, when you have your instance of OpenCV4Adroid SDK set up and configured, you may want to proceed to using OpenCV in your own application. You can learn how to do that in a separate <a class="el" href="../../d5/df8/tutorial_dev_with_OCV_on_Android.html">Android Development with OpenCV</a> tutorial. </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:36 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
